const formatTime = date => {
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    const hour = date.getHours()
    const minute = date.getMinutes()
    const second = date.getSeconds()

    return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}
const isTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()
  return `${[year, month, day].map(formatNumber).join('')} ${[hour, minute, second].map(formatNumber).join(':')}`

}

const formatNumber = n => {
    n = n.toString()
    return n[1] ? n : `0${n}`
}

const suijima = () => {
    let dataTime
    let yy = new Date().getFullYear()
    let mm = new Date().getMonth() + 1
    let dd = new Date().getDate()
    let hh = new Date().getHours()
    let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() :
        new Date().getMinutes()
    let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() :
        new Date().getSeconds()
    dataTime = `${yy}-${mm}-${dd} ${hh}:${mf}:${ss}`;
    return dataTime
}
const randomCoding = () => {
    //创建26个字母数组
    var arr = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'I', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
    var idvalue = '';
    let n = 6;//这个值可以改变的，对应的生成多少个字母，根据自己需求所改
    for (var i = 0; i < n; i++) {
        idvalue += arr[Math.floor(Math.random() * 52)];
    }
    return idvalue;
}
const getTime = (time) => { 
  let dataTime
  let yy = time.getFullYear()
  let mm = time.getMonth() + 1
  let dd = time.getDate()
  let hh = time.getHours()
  let mf = time.getMinutes() < 10 ? '0' + time.getMinutes() :
      time.getMinutes()
  let ss = time.getSeconds() < 10 ? '0' + time.getSeconds() :
      time.getSeconds()
  dataTime = `${yy}-${mm}-${dd} ${hh}:${mf}:${ss}`;
  return dataTime
}

module.exports = {
    formatTime,
    suijima,
    randomCoding,
    isTime,
    getTime,
}
